<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<!--
private Integer id;

    private String  courseName;

    private String coursePic;

    private String courseDescription;

    private Integer courseTeacher;

    private String users;

    private Integer status;


    private Double pay;
-->
<form class="layui-form layuimini-form" >
    <div class="layui-form-item">
        <label class="layui-form-label required">姓名</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="admin_name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="password" id="pass" name="admin_pass" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">登录</button>
        </div>
    </div>
</form>
<script src="layui/layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>

<script>
    layui.use(['form','upload', 'element'], function () {
        var form = layui.form,
            upload = layui.upload,
            element = layui.element,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                url: '/tologin',
                data: JSON.stringify(data.field),
                type: "post",
                contentType: "application/json",
                dataType: "json",
                success: function (res) {
                    console.log(1111111111111);
                    console.log(res);

                    if (res!=null) {
                        // var iframeIndex = parent.layer.getFrameIndex(window.name);
                        // parent.layer.close(iframeIndex);
                        alert("登录成功");
                        window.localStorage.setItem("name", res.admin_name);
                        location.href = 'index.html';
                    } else {
                        alert("登录失败");
                        location.href = 'login.html';

                    }
                },
                error:function () {
                    alert("登录失败");
                }
            })
            console.log(22222222222222222);
            // location.href="/getAllUser.html";
           // form.render("select");
            return false;

        });


        //重新加载select 标签
        form.render("select");

    });

</script>
</body>
</html>